﻿@using System.Data
@{
    Layout = "~/Areas/Mall/Views/Shared/MallLayout1.cshtml";
    DataSet set = ViewData["data"] as DataSet;
    DataTable tb1 = set.Tables[0];
    DataTable tb3 = set.Tables[2];
    DataTable tbpj= set.Tables[1];
    var dprice= Convert.ToDouble(tb1.Rows[0]["DiscountPrice"].ToString());
    var price=Convert.ToDouble(tb1.Rows[0]["Price"].ToString());
    var count = Convert.ToInt32(tb1.Rows[0]["Count"].ToString())-Convert.ToDouble(tb1.Rows[0]["PayCountTrue"].ToString());
    ViewBag.Title = tb1.Rows[0]["Name"].ToString();
}
<link rel="stylesheet" href="/Scripts/swiper/css/swiper.min.css">
<script src="/Scripts/swiper/js/swiper.min.js"></script>
<div class="swiper-container">
    <div class="swiper-wrapper">
        @{
            for (int i = 1; i <= 5; i++)
            {
                if (tb1.Rows[0]["Img" + i].ToString().Trim() != "")
                {                  
                    <div class="swiper-slide">
                        <img src="@tb1.Rows[0]["Img" + i].ToString()" />
                    </div>
                }
            }
        }
       

    </div>
</div>
<script>
    //var swiper = new Swiper('.swiper-container');
    var mySwiper = new Swiper('.swiper-container', {
        autoplay: 5000, //可选选项，自动滑动
    })
</script>





<div class="goodstitle">@tb1.Rows[0]["Name"].ToString()</div>
<div class="tclist">
    <input type="hidden" value="0"/>
    @{
        foreach (DataRow row in tb3.Rows)
        {
            <div tcid="@row["Id"]" price="@Convert.ToDouble(row["price"])">@row["name"] @row["value"] @Convert.ToDouble(row["price"])元</div>
        }
    }
  
</div>
<div class="price">
    <div class="priceZ"><strong id="xsprice">￥
                            @Html.Raw((dprice==0?price:dprice))                        
                        </strong></div>
    @{
        if (dprice>0)
        {
            <div class="priceD">￥@price</div>
        }
    }
    <div class="kuaidi">运费：@Html.Raw(Convert.ToDouble(tb1.Rows[0]["Freight"]))元</div>
</div>

<div class="gcount">
    <div onclick="jian()" class="gcountd">-</div>
    <div class="gcountd">1</div>
    <div onclick="jia()" class="gcountd">+</div>

</div>


<div class="goumai">
    <div class="gwc" onclick="goumai(0)">加入购物车</div>
    <div class="ligm" onclick="goumai(1)">立即购买</div>
</div>
<div class="twpc">
    <div style="border-bottom:#666666 3px solid; ">商品详情</div>
    <div>用户评价</div>
</div>
<div class="contentdet" id="des">
    @Html.Raw(tb1.Rows[0]["Des"].ToString())
</div>

<div class="contentdet" id="pj" style="display: none;">
    @foreach (DataRow row in tbpj.Rows)
    {
        <div class="pingjia_list">
            <div class="pj_name">
                <label style="float: left;">
                    <strong>
                        @{
        if (row["NcName"].ToString() == "")
        {
                @Html.Raw(row["PlName"])
        }
        else
        {
                @Html.Raw(row["NcName"].ToString())
        }
                        }
                    </strong>

                </label>
                <label style="font-size: 12px; color:#999;float: right;">@row["Date"].ToString().Substring(0,10)</label>
            </div>
            <div class="pjcontent">
               @Html.Raw(row["Text"])
            </div>
            <div class="pjimg_list">
                @{
        if (row["Img1"].ToString() != "")
        {
            <img src="@row["Img1"].ToString()" width="50" height="50"/>
        }
        if (row["Img2"].ToString() != "")
        {
            <img src="@row["Img2"].ToString()" width="50" height="50" />
        } if (row["Img3"].ToString() != "")
        {
            <img src="@row["Img3"].ToString()" width="50" height="50" />
        }
}
              
            </div>
            <div class="pjcontent">
                @{
        for (int i = 0; i < Convert.ToInt32(row["Rnk"].ToString()); i++)
        {
            <img src="/Images/redx.png" width="25">
        }
                }
               
            </div>
        </div>
    }
</div>
<div style="width: 100%;height: 100px;"></div>
<script>
    var pagecount = 5;
    var pagenum = 0;
    var sid = "@ViewData["id"]";
    $("#des img").css("display","block");
    //$(function() {
    //  //  getlist();
    //});
    //$(window).scroll(function() {
    //    if ($(document).scrollTop() + $(window).height() >= $(document).height()) {
    //        pagenum += 1;
    //        getlist();
    //    }
    //});
    $("#guige img").css("width","100%");
    $("#guige img").css("display","block");
    $(".tclist div").click(function() {
        $(".tclist div").css("background", "red");
        $(this).css("background", "#FF9500");
        $("#xsprice").html("￥" + $(this).attr("price"));
        $(".tclist input:eq(0)").val($(this).attr("tcid"));
    });

    $(".twpc div").click(function() {
        $(".twpc div").css("border-bottom", "none");
        $(this).css("border-bottom", "#666666 3px solid");
        $(".contentdet").hide();
        $(".contentdet:eq(" + $(this).index() + ")").show();
    });

    function goumai(ope) {
        var gid = "@tb1.Rows[0]["Id"]";
        var tcid = $(".tclist input:eq(0)").val();
        var count = $(".gcount div:eq(1)").html();
        var tc = $(".tclist div").size();

        if (tc > 0) {
            if (tcid == 0) {
                alert("请选择产品规格！");
                $("#des").hide();
                $("#guige").show();
                $("#pj").hide();
                return false;
            }
        }
        $.post("@Url.Action("AddShopCar")", { gid: gid, tcid: tcid, count: count,ope:ope }, function(row) {
            if (ope == 1) {
                location.href = "/Mall/order/OrderList?sid=1";
            } else {
                if (row > 0) {
                    alert("已加入购物车！");
                } else {
                    alert("加入购物车失败！");
                }
            }

        });
    }


    function jia() {
        var totalcount =@count;
        var count= $(".gcount div:eq(1)").html();
        var temp = parseFloat(count) + 1;
        if (temp > totalcount) {
            alert("您所选择的商品数量超过了库存！");
            return false;
        }

        $(".gcount div:eq(1)").html(temp);
    }

    function jian() {
        var totalcount=@count;
        var count = $(".gcount div:eq(1)").html();
        var temp = parseFloat(count) - 1;
        if (temp > totalcount) {
            alert("您所选择的商品数量超过了库存！");
            return false;
        }
        if (temp < 1) {
            temp = 1;
        }
        $(".gcount div:eq(1)").html(temp);
    }


    @*function getlist() {
        $.post("@Url.Action("Pjlist")", { pageCount: pagecount, pageIndex: pagenum * pagecount, gid: "@Request["gid"]" }, function(data) {

            var obj = JSON.parse(data);
            var str = "";
            for (var i = 0; i < obj.data.length; i++) {
                var item = obj.data[i];
                str += "<div class=\"g_pj\">" +
                    "<div class=\"pj_l\">" +
                    "<img src=\"" + item.Img + "\" />" +
                    "<p>" + item.Name.substring(0, 1) + "****</p><br>" +
                    "</div>" +
                    "<div class=\"pj_r\">" +
                    "<div class=\"pj_bs\">" + item.Text + "</div>" +
                    "<div class=\"pj_bs\">";
                str += item.Img1 == "" ? "" : "<img src=\"" + item.Img1 + "\" class=\"pj_im\"  />";
                str += item.Img2 == "" ? "" : "<img src=\"" + item.Img2 + "\" class=\"pj_im\"  />";
                str += item.Img3 == "" ? "" : "<img src=\"" + item.Img3 + "\" class=\"pj_im\"  />";
                str += "</div>" +
                    "<div class=\"pj_bs\">";
                for (var j = 0; j < item.Rnk; j++) {
                    str += "<img src=\"/Images/redx.png\" class=\"pj_rnk\"/>";
                }
                str += "</div>" +
                    "<div class=\"pj_tm\">" + item.Date.substring(0, 10) + "</div>" +
                    "</div>" +
                    "</div>";
            }
            $("#pj").append(str);
        });
    }*@

    function fenqi() {
        var gid = "@tb1.Rows[0]["Id"]";
        var tcid = $(".tclist input:eq(0)").val();
        var count = $(".gcount div:eq(1)").html();
        var tc = $(".tclist div").size();

        if (tc > 0) {
            if (tcid == 0) {
                alert("请选择产品规格！");
                $("#des").hide();
                $("#guige").show();
                $("#pj").hide();
                return false;
            }
        }
        var att=gid+"_"+tcid+"_"+count;
        location.href = "/mall/fqorder/fqdes?attr="+att;
    }
</script>